package cn.com.servlet;

import cn.com.bean.TraineeBean;
import cn.com.dao.impl.TraineeDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class ServletChj extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //模糊查询
        //获取输入框中的值
        String keywords = req.getParameter("keywords");//进行字符串拼接
        String like_keywords = "%" + keywords + "%";
        //创建一个List集合用来接收selectwithlike()方法返回的值
        System.out.println("88888888888888888888");
        List<TraineeBean> list = new TraineeDaoImpl().findByName(like_keywords);//保存
        System.out.println("99999999999999999999");
        if (list != null) {
            req.setAttribute("trainee", list);//请求转发
            for (int i = 0; i < list.size(); i++) {
                System.out.println("list:" + list.get(i).getName());
            }
            req.getRequestDispatcher("moHuFind.jsp").forward(req, resp);

        }
        System.out.println("......222222");
        List<TraineeBean> list1 = new TraineeDaoImpl().findAll();
        System.out.println(list1 + "1111111111111111111");

        if (list1 != null) {
            req.setAttribute("trainee", list1);//请求转发
            for (int i = 0; i < list1.size(); i++) {
                System.out.println("list1:" + list1.get(i).getName());
            }
            req.getRequestDispatcher("moHuFind.jsp").forward(req, resp);
            System.out.println("********");
        }

        

    }
}

